<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script>
<script type="text/javascript">
function editcatsub(){
	var e = document.getElementById('typep');
	valid = e.options[e.selectedIndex].value;
	valtext = e.options[e.selectedIndex].text;
	document.getElementById("editsubtmp").value = valtext;
	document.getElementById("id_cattmp").value = valid;
}


function updatecatsub(){
	id = document.getElementById("id_cattmp").value;
	alert(id);
}
function deletecatsub(){
	id = document.getElementById("id_cattmp").value;
	alert(id);
}
function updatecatsub(){
	id = document.getElementById("id_cattmp").value;
	var text = document.getElementById('editsubtmp').value;
	url = "<?php echo base_url();?>"+"/addmincont/updatecatsub/";
	var data ={'ref':id,'name':text};
	$.ajax({
		type : 'POST',
		url: url,
		data:data,
		dataType:'html',
		success: function(result){
			if(result==1){
				alert('Update Product Successfull');
				window.location.reload(true);
			}else{
				alert('Error connect to DB');
			}
		}
	});//end ajax	
}
function deletecatsub(id){
	id = document.getElementById("id_cattmp").value;
	var text = document.getElementById('editsubtmp').value;
	var r=confirm("Are you sure Delete Categories! "+text);
	if (r==true){
		url = "<?php echo base_url()?>/addmincont/delcatesubsub/";
		var data ={ref:id};
		$.ajax({
			type : 'POST',
			url: url,
			data:data,
			dataType:'html',
			success: function(result){
				if(result==1){
					alert('Delete Product Successfull');
					window.location.reload(true);
				}else{
					alert('Error connect to DB');
				}
			}
		});//end ajax
	}else{
		return false;
	}	
}
</script>
<?php
echo "<br/>Edit cat sub<br/>";
echo '<select name = "typep" id = "typep" onchange="editcatsub();">';
			echo '<option value="">Categories Type</option>';
			$couttype = count($catetype);
			for($i=0;$i<$couttype;$i++){
				$type = $catetype[$i]['cat_type_name'];
				echo '<optgroup label="'.$type.'">';
				$couttypesub = count($catetype[$i][0]);
				for($j=0;$j<$couttypesub;$j++){
					echo '<option value="'.$catetype[$i][0][$j]['cat_type_sub_id'].'">'.$catetype[$i][0][$j]['cat_type_sub_name'].'</option>';
				}
			}
echo '</select>';
echo "<pre><input type='text' value='' id='editsubtmp'>";
echo '<input type="button" value="Update" id="updatetmp" onclick="updatecatsub();">';
echo '<input type="button" value="Delete" id="deletesubtmp" onclick="deletecatsub();">';
echo "<input type='hidden' value='' id='id_cattmp' >";
?>